package io.renren.service.impl;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.dao.TeamDao;
import io.renren.entity.TeamDto;
import io.renren.entity.TeamEntity;
import io.renren.service.TeamService;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

@Service("teamService")
public class TeamServiceImpl extends ServiceImpl<TeamDao, TeamEntity> implements TeamService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		Page<TeamEntity> page = this.selectPage(new Query<TeamEntity>(params).getPage(), new EntityWrapper<TeamEntity>());

		return new PageUtils(page);
	}

	@Override
	public TeamDto countTeamByMemberId(Long memberId) {
		return baseMapper.countTeamByMemberId(memberId);
	}

	@Override
	public PageUtils countTeamByHigher(Map<String, Object> params) {
		Long id = (Long) params.get("id");
		Integer level = (Integer) params.get("level");
		Page<TeamDto> page = new Query<TeamDto>(params).getPage();
		page = page.setRecords(baseMapper.countTeamByHigher(page, level, id));
		return new PageUtils(page);
	}
}
